<template>
    <div class="app-container">
        <el-card shadow="never">
            <!-- 条件查询 -->
            <el-form v-show="showSearch" ref="queryForm" :model="queryParams" label-width="120px" @keyup.enter.native="submitSearch" @submit.native.prevent>
                <el-row>

                    <el-col :md="6" :sm="12">
                        <el-form-item label="订单号:" prop="order_id.value">
                            <el-input  :rows="4" v-model="queryParams.order_id.value" placeholder="请输入订单号" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item class="ele-text-right" label-width="50px">
                            <el-button type="primary" size="mini" @click="submitSearch" icon="el-icon-search" class="ele-btn-icon">搜索 </el-button>
                            <el-button @click="resetQuery" size="mini" icon="el-icon-refresh">重置</el-button>

                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>

            
            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                    <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="open" v-hasPermi="api.add">添加</el-button>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="initIndex" :columns="columns" printId="#quickadmin"></right-toolbar>
            </el-row>

            <el-row>
                <el-col :span="1.5">
                    <el-upload
                        class="upload-demo"
                        ref="upload"
                        :action="api.upload"
                        :on-preview="handlePreview"
                        :on-remove="handleRemove"
                        :on-success="handleUploadSuccess"
                        :on-error="handleUploadError"
                        :file-list="fileList"
                        :auto-upload="false">
                        <el-button slot="trigger" size="small" type="primary">选择文件</el-button>
                        <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传手工订单</el-button>
                    </el-upload>
                </el-col>
            </el-row>
            <el-tabs v-model="activeTab" @tab-click="handleStatus" type="border-card">
                <el-tab-pane v-for="(item, index) in codes" :key="index" :label="item.label" :name="item.value.toString()">
            <!-- 列表 -->
            <qa-table
                :source="tableData"
                :columns="columns"
                :selection="true"
                :loading="loading"
                @sortChange="sortChange"
                @statusChange="statusChange"
                @selectionChange="selectionChange"
                id="quickadmin"
            >
            </qa-table>
            </el-tab-pane>
          </el-tabs>
            <!-- 分页 -->
            <pagination :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="initIndex" />
        </el-card>

        <!-- 编辑弹窗 -->
       <el-dialog :title="!disabled ? '编辑' : '详情'" :visible="editOpen"  :before-close="beforeClose" destroy-on-close>
            <EditForm ref="editForm" :findFormData="findFormData"  :disabled="disabled" @submitForm="submitForm" :editFormParams="editFormParams" @editFormCancel="beforeClose" />
        </el-dialog>

    </div>
</template>

<script>
import { curdMixin } from '@/mixins/curdMixin'
import EditForm from './EditFormCom'
export default {
    name: 'Curd',
    mixins: [curdMixin],
    components: { EditForm },
    
    data() {
        return {
            fileList: [],
            // table结构
            columns: [
                {
                    visible: true,
                    label: '订单号',
                    prop: 'order_id',
                },
                {
                    visible: true,
                    label: '物流单号',
                    prop: 'tracking_number',
                },
                {
                    visible: true,
                    label: '状态',
                    prop: 'status',
                },
                {
                    visible: true,
                    label: '返回信息',
                    prop: 'error',
                },
                {
                    visible: true,
                    label: '添加时间/处理时间',
                    prop: 'updatetime',
                },

            ],
            // 接口地址
            api: {
                index: `/admin/orderback/index`,
                find: `/admin/orderback/find`,
                add: `/admin/orderback/add`,
                edit: `/admin/orderback/edit`,
                delete: `/admin/orderback/delete`,
                export: `/admin/orderback/export`,
                status: `/admin/orderback/status`
            },
            editFormParams: {
            },
            pageInfo: {
                sort: 'id',
            },
            primaryKey: 'id',
            // 搜索表单是否展开
            searchExpand: false,
              //是否展示搜索
            showSearch: true,
            // 查询参数
            queryParams: {
                order_id: { value:undefined, op: '%like%'},
                status: { value:[], op: '='},
            },
            codes: [
                { label: '全部', value: '' },
                { label: '等待', value: '1' },
                { label: '成功', value: '2' },
                { label: '失败', value: '3' },
             ],

        }
    },
    created () {
        this.initIndex()
    },
    watch: {
        
    },
    methods: {
        // 案列：当前组件格式化方法
        testFormatter(prop) {
            return prop
        },
        handleStatus(tab) {
            this.queryParams.status.value = tab.name
            this.submitSearch()
        },
        handlePreview(file) {
            console.log(file);
        },
        handleRemove(file, fileList) {
            console.log(file, fileList);
        },
        // 上传成功回调
        handleUploadSuccess(res) {
            this.loading = false
            if (res.code == 1) {
                this.$message.success('上传成功');
                this.initIndex();
            } else {
                this.$message({
                    type: 'error',
                    message: '上传失败'+res.msg,
                })
            }
        },
        // 上传失败
        handleUploadError() {
            this.$message({
                type: 'error',
                message: '上传失败',
            })
        },
        submitUpload() {
            this.loading = true
            this.$refs.upload.submit();
        },
        
    }
}
</script>
<style lang="scss">
.btn-mar {
    margin: 5px !important;
}
</style>
